package com.yc.springmvc.biz;

import com.yc.springmvc.bean.Person;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

@Service
public class UserBiz {

    private Set<Person> persons = new HashSet<>(){
        {
            Person person = new Person();
            person.setName("yyyl");
            person.setPwd("1234");
            this.add(person);
        }
    };

    public Person login(Person person) throws BizException {
        Person findPerson = persons.stream().filter(p -> {
            return p.getName().equals(person.getName()) && p.getPwd().equals(person.getPwd());
        }).findFirst().orElse(null);

        if (findPerson == null){
            throw new BizException("用户名或者密码错误");
        }

        return findPerson;
    }

}
